package cn.csxw.openchina.dagger2.presenter;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import cn.csxw.openchina.entity.ResultState;
import cn.csxw.openchina.entity.bean.ActiveBean;
import cn.csxw.openchina.entity.bean.OsChinaBean;
import cn.csxw.openchina.ui.activity.CircleFriendsActivity;
import cn.csxw.openchina.ui.fragment.discoverFragment.FriendFragment;
import cn.csxw.openchina.utils.Global;
import retrofit2.Call;

/**
 * 发现---》朋友圈
 */

public class CircleFriendsActivityPresenter extends BasePresenter {
    FriendFragment mFriendFragment;
    private ArrayList<ActiveBean> mActivies;

    @Inject
    public CircleFriendsActivityPresenter(FriendFragment friendFragment) {
        mFriendFragment = friendFragment;
    }

    @Override
    protected void processData(OsChinaBean data) {
        if (data != null) {
            mActivies = (ArrayList<ActiveBean>) data.activies;
            if(mActivies== null || mActivies.size()==0){
                mFriendFragment.updateData(ResultState.LOAD_EMPTY);
                Global.showToast("没有人发好友圈哦");
                mFriendFragment.loadMoreCompleted();
                mFriendFragment.mSrfLayout.setRefreshing(false);
                return;
            }
            if (mFriendFragment.mAdapter.getData().size()!= 0) {
            mFriendFragment.mAdapter.addData(mActivies);
            mFriendFragment.loadMoreCompleted();
        } else {
            mFriendFragment.mAdapter.setData(mActivies);
            mFriendFragment.mSrfLayout.setRefreshing(false);
        }
    }

    }

    @Override
    public void callNetWork(Object... params) {
        if (params.length != 4 || !(params[0] instanceof String) || !
                (params[1] instanceof Integer) || !(params[2] instanceof Integer)
                || !(params[3] instanceof Integer)) {
            throw new IllegalArgumentException("参数必需是String,int ," +
                    " int ,int,四个类型，在朋友圈中");
        }
        Call<OsChinaBean> findInfo = mOsChinaServer.getFindInfo((String) params[0],
                (int) params[1], (int) params[2], (int) params[3]);
        findInfo.enqueue(mCallback);

    }
}
